package org.dtrd.modules.util;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.dtrd.common.exception.JeecgBootException;
import org.dtrd.config.system.Constant;

/**
 * 打卡工具类
 * @author qr
 * @date 2022/4/2 14:29
 */
@Slf4j
public class SigninUtil {

    public static String floatToInt(String floatVal) {
        if (StrUtil.isNotBlank(floatVal)) {
            String[] strings = floatVal.split("\\.");
            return strings[0];
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(floatToInt("100"));
    }

    /**
     * 根据打卡类型获取打卡计划的全名称,
     * @param subType 没有子类的打卡传个 0
     */
    @SuppressWarnings("all")
    public static String getSigninName(Integer type, Integer subType) {
        try {
            Constant.RecordType recordType = Constant.RecordType.valueOf(type);
            if (recordType == null) {
                throw new JeecgBootException("打卡类型错误: type = " + type);
            }
            switch (recordType) {
                case SUGAR: {
                    Constant.SugarRecordType sugarRecordType = Constant.SugarRecordType.valueOf(subType);
                    return sugarRecordType.getName() + recordType.getName();
                }
                case BLOOD_PRESSURE: {
                    Constant.BloodPressureRecordType bloodPressureRecordType = Constant.BloodPressureRecordType.valueOf(subType);
                    return bloodPressureRecordType.getName() + recordType.getName();
                }
                case MEDICAL: {
                    Constant.MedicalRecordType medicalRecordType = Constant.MedicalRecordType.valueOf(subType);
                    return recordType.getName() + "(" + medicalRecordType.getName() + ")";
                }
                case INSULIN: {
                    Constant.InsulinRecordType insulinRecordType = Constant.InsulinRecordType.valueOf(subType);
                    return recordType.getName()+"("+insulinRecordType.getName()+")";
                }
                case DIET: {
                    Constant.FoodRecordType foodRecordType = Constant.FoodRecordType.valueOf(subType);
                    return foodRecordType.getName();
                }
                case SPORT:
                case KETONE:
                case WEIGHT:
                case WAIST:
                case SLEEP:
                    return recordType.getName();
            }
        }catch (NullPointerException e) {
            log.error("打卡类型错误: type = {}, subType = {}", type, subType);
            return null;
        }
        return null;
    }
}
